package com.wikidot.designpatterns.builder;

import java.util.Properties;
import java.util.StringTokenizer;

/**
 * Wrapper of the construction process. This class holds instance of the target
 * builder, parses the input and call builder's methods in proper way
 * (construction contract). Parsing the input means processing information which
 * leads to construction of the product.
 */
class LabelCreationDirector {
	/**
	 * Instruct concrete builder to build the label by following the
	 * construction contract.
	 * 
	 * @param builder
	 * @return
	 */
	public Label createLabel(LabelBuilder builder, Properties labelInfo) {
		builder.setId(labelInfo.getProperty("id"));
		builder.setDescription(labelInfo.getProperty("description"));
		StringTokenizer tokenizer = new StringTokenizer(labelInfo
				.getProperty("tags"), "+");
		while (tokenizer.hasMoreTokens()) {
			builder.setTag(tokenizer.nextToken());
		}
		return builder.getLabel();
	}
}
